<template>
	<view class="home">
		<view class="nav_top">
			<view class="nav_top_left" @click="app_ctl(1)" :class="ctl_type==1?'act_ctl':''">
				<text>APP控制</text>
			</view>
			<view class="nav_top_center">
				控制器状态：<text>正常</text>
			</view>
			<view @click="ctl_type=2,jiasu_test()" :class="ctl_type==2?'act_ctl':''" class="nav_top_right">
				<view class="top-icon-wrap">
					<image class="top-icon" src="/static/home/play.png"></image>
				</view>
				<text>开始</text>
			</view>
		</view>

		<view class="nav_top">
			<view class="nav_top_left"  @click="app_ctl(0)" :class="ctl_type==0?'act_ctl':''">
				<text>车辆控制</text>
			</view>
			<view class="nav_top_center">
				故障状态：无
			</view>
			<view class="nav_top_right">
				<view class="top-icon-wrap">
					<image class="top-icon" src="/static/home/rescord.png"></image>
				</view>
				<text>记录</text>
			</view>
		</view>


		<view class="tubiao">
			<l-echart force-use-old-canvas="false" ref="chartRef" @finished="init"></l-echart>
			<view class="tubiao_top">
				<view>
					<text>{{juli}}</text> Km/h
				</view>
				<view>
					<text>{{zhuansu}}</text> Rpm
				</view>
			</view>
			<view class="tubiao_bom">
				<view class="tubiao_bom_one">
					<view>R</view>
					<view>1</view>
					<view>2</view>
					<view>3</view>
					<view>S</view>
				</view>
				<view class="tubiao_bom_two">
					<view class="tubiao_bom_two_left">
						<view class="tubiao_bom_two_left_top">
							油门指令(V)
						</view>
						<view class="tubiao_bom_two_left_bom">

							<view class="tubiao_bom_two_left_bom_left">
								<image src="/static/jian1.png"></image>
							</view>
							<view class="tubiao_bom_two_left_bom_cent">
								<input type="number" value="0">
							</view>
							<view class="tubiao_bom_two_left_bom_right">
								<image src="/static/jia1.png"></image>
							</view>
						</view>
					</view>

					<view class="tubiao_bom_two_left">
						<view class="tubiao_bom_two_left_top">
							油门电压(V)
						</view>
						<view class="tubiao_bom_two_left_bom">
							<input disabled type="number" :value="dianya.toFixed(1)">
						</view>
					</view>
				</view>

				<view class="tubiao_bom_three" @click="tz('/pagesB/home/lanya')">
					<view>
						<image src="/static/lan.png"></image>
					</view>
					<view class="tubiao_bom_three_bom">
						连接蓝牙
					</view>
				</view>

				<view class="tubiao_bom_four">
					<view class="tubiao_bom_four_top">
						<view>
							<view>母线电压(V)</view>
							<view>
								{{muxian_v.toFixed(1)}}
							</view>
						</view>
						<view class="line">

						</view>
						<view>
							<view>母线电流(A)</view>
							<view>
								{{muxian_a.toFixed(1)}}
							</view>
						</view>
					</view>
					<view class="lines">

					</view>

					<view class="tubiao_bom_four_top">
						<view>
							<view>相线电流(A)</view>
							<view>
								{{xiangxian.toFixed(1)}}
							</view>
						</view>
						<view class="line">

						</view>
						<view>
							<view>弱磁电流(A)</view>
							<view>
								{{ruoci.toFixed(1)}}
							</view>
						</view>
					</view>

					<view class="lines">

					</view>
					<view class="tubiao_bom_four_top">
						<view>
							<view>电机温度(℃)</view>
							<view>
								{{dianji.toFixed(1)}}
							</view>
						</view>
						<view class="line">

						</view>
						<view>
							<view>MOS温度(℃)</view>
							<view>
								{{mos.toFixed(1)}}
							</view>
						</view>
					</view>
				</view>

				<view class="tubiao_bom_five">
					<view @click="app_click(0)">
						充电
					</view>
					<view @click="app_click(1)">
						脚撑
					</view>
					<view @click="app_click(2)">
						低速
					</view>
					<view style="width: 256rpx;" @click="app_click(3)">
						电子制动系统
					</view>

				</view>
				
				<view class="tubiao_bom_fives tubiao_bom_five">
				
					<view @click="app_click(4)">
						高速
					</view>
					<view @click="app_click(5)">
						倒车
					</view>
					<view @click="app_click(6)">
						开始
					</view>
					<view @click="app_click(7)">
						巡航
					</view>
					<view @click="app_click(8)">
						警报
					</view>
				
				</view>

			</view>
		</view>



		<tabbar :lang="lang" :current="0"></tabbar>
	</view>
</template>

<script>
	var app = getApp();
	import uniPopup from "@/components/uni-popup/uni-popup.vue";
	import * as echarts from '@/uni_modules/lime-echart/static/echarts.min'
// import { url } from "../../../uni_modules/uv-ui-tools/libs/function/test";


	export default {
		components: {
			uniPopup
		},
		data() {
			return {
				time_head:null,
				chesu: [
					["蓝牙兼容模式", "CAN调试模式"]
				],
				lang_arr: [
					["中文", "英文"]
				],
				new_name: "",
				login: true, //是否登录
				userType: 0, //嘉宾状态 0.未申请 1.待审核 2.通过 3.拒绝
				avatar: '', //头像
				nickname: '艾克里里', //昵称
				inviteCode: '', //邀请码
				userinfo: null,
				lan_bug: 0,
				ss: [],
				dev_name: "",
				is_pri: "0",
				is_yuancheng: 0,
				lang: 0,
				btl_arr: [
					["点击选择", "2400", "4800", "9600", "19200", "38400", "57600", "115200"]
				],
				btl: 0,
				chartData: {},

				option: {

				},
				zs: 0,
				cs: 0,
				deviceList: [],
				
				// 当前连接的蓝牙设备信息
				deviceInfo: {},
				// 当前连接的蓝牙设备的服务信息
				serviceInfo: {},
				// 支持 write 的特征值信息
				writeCharacteristicsInfo: {},
				// 支持 notify 或者 indicate 的特征值信息
				notifyCharacteristicsInfo: {},
				is_yuancheng:0,
				is_biao:0,
				h_i:0,
				h_f:0x00,
				h_time:null,
				
				
				muxian_v:0,
				muxian_a:0,
				zhuansu:0,
				xiangxian:0,
				ruoci:0,
				mos:0,
				miao:120,
				juli:0,
				nub_times:null,
				dumiao:0,
				time:0,
				end_jiasu_time:null,
				ctl_type:0,
				h_i:0,
				che_xintiao:0,
				dianji:0,
				dianya:0
				
				
				
			};
		},
		onReady() {
			// setTimeout(()=>{
			// 	this.$refs.chart.resize({width: 175, height: 175})
			// },100)
		},
		onHide() {
			if(this.time_head){
				clearInterval(this.time_head)
			}
		},
		onUnload(){
			if(this.time_head){
				clearInterval(this.time_head)
			}
		},
		onLoad() {
			uni.hideTabBar();
		
			// this.getInvite();

			// share() {
			// 	this.$refs.popup1.open();
			// },
			// // 分享好友
			// shareFriend() {
			// 	this.$refs.popup1.close();
			// },
			// this.baocun_lan()

		},
		mounted() {
			// 把 echarts 传入 

			setTimeout(() => {
				this.zhuang();
			}, 100)
			console.log(11111)



		},
		onShow() {
			
	
			
			let send_val = 2.4 * 1000
			let send_val_h = parseInt(send_val / 256);
			let send_val_l = parseInt(send_val % 256);
			
			console.log("send_val_h",send_val_h)
			console.log("send_val_l",send_val_l)
			
			// 0x00 0x01
			let values = 0x03 * 256 + 0x01;  //高字节*256+低字节  0x00 0x01  = 0x00 * 256 + 0x01
			
			let data = this.$util.set_bit(values, 5, 8,4);
			console.log(9797,data);
			
		
			this.lang = uni.getStorageSync('lang')
			
			if (this.lang == 1) {
				this.chesu = [
					["Bluetooth", "CAN"]
				]
				this.lang_arr = [
					["chinese", "English"]
				]
			} else {
				this.chesu = [
					["蓝牙兼容模式", "CAN调试模式"]
				]
				this.lang_arr = [
					["中文", "英文"]
				]
			}


			var ss = uni.getStorageSync('dev_data');
			console.log("mv22", ss.softstart_level_index)

			this.ss = ss;

			if (uni.getStorageSync('token')) {
				// this.get_user_info()
			}


			let lan_bug = uni.getStorageSync('lan_bug')
			if (lan_bug) {
				this.lan_bug = uni.getStorageSync('lan_bug')
			}
			
			if (app.globalData.connected == true) {
				
				if(app.globalData.is_yuancheng){
					this.ctl_type = app.globalData.is_yuancheng
				}
				
				this.is_biao = 0;
				
				this.deviceList = uni.getStorageSync('deviceList');
				this.serviceInfo = uni.getStorageSync('serviceInfo');
				this.writeCharacteristicsInfo = uni.getStorageSync('writeCharacteristicsInfo');
				
				
				this.notifyCharacteristicsInfso = uni.getStorageSync('notifyCharacteristicsInfo');
				this.deviceInfo = uni.getStorageSync('deviceInfo');
					
				// this.get_home_data();
				setTimeout(()=>{
					//发送读取
					if(this.time_head){
						clearInterval(this.time_head)
					}
					
					
					this.time_head = setInterval(()=>{
						if(this.che_xintiao == 0){
							this.heartbeat()
						}
					},300);
				},50)
			}
			
			 this.sloads();

		},
		methods: {
			throttle(value){
			
				this.che_xintiao = 1;
				this.data = uni.getStorageSync('dev_data');
				
				setTimeout(()=>{
					uni.onBLECharacteristicValueChange((res) => {
						const value = Array.prototype.map.call(new Uint8Array(res.value), (bit) => bit)
						console.log("发送控制参数监听到的参数",value)
						console.log("发送控制参数监听到的参数cl",this.$util.ab2hext_str(value))
						this.che_xintiao  = 0;
						//执行失败处理 777777
					})
					
					 console.log("发送控制---",temp)		
					 let strArray = new Uint8Array(temp)
					 const buffer = strArray.buffer		  
					// 向低功耗蓝牙设备特征值中写入二进制数据
					 uni.writeBLECharacteristicValue({
					  // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
					  deviceId: this.deviceInfo.deviceId,
					  // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
					  serviceId: this.serviceInfo.uuid,
					  // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
					  characteristicId: this.writeCharacteristicsInfo.uuid,
					  // 这里的value是ArrayBuffer类型
					  value: buffer,
					  writeType: 'writeNoResponse',
					  success(res) {
						  
						console.log("发送控制成功")
				
					  },
					  fail(error) {
							uni.hideLoading();	
						console.log('fail')
						console.log(error)
					  
						if (error.errCode) {
						  uni.showToast({ title: errorCode[error.errCode], icon: 'none' })
						} else if (error.errMsg) {
						  uni.showToast({ title: error.errMsg, icon: 'none' })
						} else {
						  uni.showToast({ title: 'fail', icon: 'none' })
						}
					  },
					})
					
				},300)
				
			},
			app_click(type){
				
				
				
				
			},
			app_ctl(type){
				
				if(type == this.ctl_type){
					return;
				}
				let that = this;
				if(app.globalData.connected != true){
					if(that.lang == 0){
						uni.showToast({
						  title: '需要先连接设备',
						  icon: 'none',
						  duration: 1000
						})
					}else{
						uni.showToast({
						  title: 'We need to connect the device first',
						  icon: 'none',
						  duration: 1000
						})
					}
					return;
				}
				this.ctl_type = type;
				
				let h_i = this.h_i;
				if(h_i>=100){
					this.h_i = 0;
				}else{
					this.h_i++;
				}
				//停止心跳 并发送对应的数据
				let temp = [];
				if(type == 0){
					//车辆控制
					//0xaa,  0x0c,    0x00,    0x10,     0x01, 0x01
					//报文头	 报文长度   帧序列号	帧数据	设备id ，报文命令
					  temp = this.$util.CRC16Modbus([
							0xaa,0x0c,0x00, 0x10, 0x01, 0x07, 0x08, h_i, 0x01, 0x00, 0x00, 0x00
					 ]);
				}else{
					//app控制
					//0xaa,  0x0c,    0x00,    0x10,     0x01, 0x01
					//报文头	 报文长度   帧序列号	帧数据	设备id ，报文命令
					  temp = this.$util.CRC16Modbus([
					 		0xaa,0x0c,0x00, 0x10, 0x01, 0x07, 0x08, h_i, 0x00, 0x00, 0x00, 0x00
					 ]);
				}
				this.che_xintiao = 1;
					
				this.data = uni.getStorageSync('dev_data');
				
			
				setTimeout(()=>{
					uni.onBLECharacteristicValueChange((res) => {
						const value = Array.prototype.map.call(new Uint8Array(res.value), (bit) => bit)
						console.log("发送控制参数监听到的参数"+type,value)
						console.log("发送控制参数监听到的参数cl",this.$util.ab2hext_str(value))
						this.che_xintiao  = 0;
					})
					 console.log("发送控制---",temp)		
					 let strArray = new Uint8Array(temp)
					 const buffer = strArray.buffer		  
					// 向低功耗蓝牙设备特征值中写入二进制数据
					 uni.writeBLECharacteristicValue({
					  // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
					  deviceId: this.deviceInfo.deviceId,
					  // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
					  serviceId: this.serviceInfo.uuid,
					  // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
					  characteristicId: this.writeCharacteristicsInfo.uuid,
					  // 这里的value是ArrayBuffer类型
					  value: buffer,
					  writeType: 'writeNoResponse',
					  success(res) {
						console.log("发送控制成功")
					  },
					  fail(error) {
							uni.hideLoading();	
						console.log('fail')
						console.log(error)
					  
						if (error.errCode) {
						  uni.showToast({ title: errorCode[error.errCode], icon: 'none' })
						} else if (error.errMsg) {
						  uni.showToast({ title: error.errMsg, icon: 'none' })
						} else {
						  uni.showToast({ title: 'fail', icon: 'none' })
						}
					  },
					})
					
				},300)
				
				
			},
			jiasu_test(){
				let that = this;
				if(app.globalData.connected != true){
					if(that.lang == 0){
						uni.showToast({
						  title: '需要先连接设备',
						  icon: 'none',
						  duration: 1000
						})
					}else{
						uni.showToast({
						  title: 'We need to connect the device first',
						  icon: 'none',
						  duration: 1000
						})
					}
					return;
				}
				
				
				console.log("开始测试11111111111111111111111111111",app.globalData.max_zs_time);
				if(app.globalData.max_zs_time && app.globalData.max_zs_time != 0){
					
					if(that.lang == 0){
						uni.showToast({
						  title: '正在加速测试',
						  icon: 'none',
						  duration: 1000
						})
					}else{
						uni.showToast({
						  title: 'Accelerating testing',
						  icon: 'none',
						  duration: 1000
						})
					}
					return;
				}
				
				
				this.miaoshus()
			},
			miaoshus(){
			
				//定时任务需要是关闭的
				if(this.nub_times){
					clearInterval(this.nub_times)
				}
				
				console.log("开始测试155555555555555555555555");
				
				//开始获取15秒内的最高速度
				app.globalData.max_zs = 0;
				app.globalData.max_zs_time = 1;
				app.globalData.max_zs_miao = 0;
				
				console.log("开始测试44444444444444444");
				//转速为0 停止  到达120秒也停止
				
			},
			get_user_info(){
				// uni.showLoading({
				// 	title: 'loading',
				// 	mask:true
				// });
				//登陆
					let _this = this;
					this.$api.request('/api/user/getUserInfo', {}, '', function(res){
						console.log(res);
						 // uni.hideLoading(); //隐藏loading
						if(res.code == 1) {
							_this.userinfo = res.data
							console.log(_this.userinfo,776)
							uni.setStorageSync('user_type', res.data.type);
							uni.setStorageSync('user_uuid', res.data.dev_id);
							// uni.setStorageSync('userinfo', res.data);
						}else{
							uni.showToast({
								title: res.msg,
								icon:"none"
							})
						}
					});
			},
			sloads(){
				
				app.globalData.max_zs_time = 0;
					// this.yundong();
				var that  = this;
			
				that.get_locan();
						
				if(uni.getStorageSync('token')){
					this.get_user_info()
				}
				
				
				
			},
			end_jiasu(){
				if(this.end_jiasu_time){
					clearTimeout(this.end_jiasu_time);
				}
				
				that.max_speed = app.globalData.max_zs;
				that.time = app.globalData.max_zs_miao;
				
				app.globalData.max_zs = 0;
				app.globalData.max_zs_time = 0;
				app.globalData.max_zs_miao = 0;
				that.dumiao = 0;
				that.xinxi(that.max_speed,that.time)
				 // = {max_speed:max_speed_str,time:time_str};
				if(this.nub_times){
					clearInterval(this.nub_times)
				}
			},
			is_chesu(){
				//
				console.log("有转速了，开始最高车速s");
				
				app.globalData.max_zs_time = 2;
				
				if(this.lang ==0){
					
					 uni.showToast({
							  title: '开始测试测速  '+this.miao+'秒后结束',
							  icon: 'none',
							  duration: 1000
							})
				}else{
					 uni.showToast({
							  title: 'Start testing and speed measurement, and end after '+this.miao+' seconds',
							  icon: 'none',
							  duration: 1000
							})
				}
				
					console.log("寻找最高车速");
				let that = this;
				that.dumiao = 0;
				that.dingshi();
				//开始读秒时间
				this.end_jiasu_time = setTimeout(function(){
						console.log("读秒结束33333333333");
					if(app.globalData.max_zs_time == 2){
						if(that.nub_times){
							clearInterval(that.nub_times)
						}
						
						that.max_speed = app.globalData.max_zs;
						that.time = app.globalData.max_zs_miao;
						
						app.globalData.max_zs = 0;
						app.globalData.max_zs_time = 0;
						app.globalData.max_zs_miao = 0;
						that.dumiao = 0;
						
						that.xinxi(that.max_speed,that.time)
										
						
						 // = {max_speed:max_speed_str,time:time_str};
							
						if(this.nub_times){
							clearInterval(this.nub_times)
						}
					}	
					
				},this.miao*1000);
			},
			xinxi(max_speed_str,time_str){
				
				this.$api.request('/api/user/max_speed', {max_speed:max_speed_str,time:time_str}, '', function(res){
					 console.log(res);
				});
			},
			dingshi(){
				
			
				if(this.nub_times){
					clearInterval(this.nub_times)
				}
				let that = this;
				
				this.nub_times = setInterval(function () {
				  that.dumiao++;
				  console.log("加速测试时间...",that.dumiao)
				}, 10)
			},
			get_locan(){
					
					let that = this;
					
				    var lat, lng;
				    let _locationChangeFn = function(res) {
						//motor_speed
						let speed = res.speed;
						if(speed<=0){
							that.time_che = 0;
						}
						//转速需要大于0
						if(that.zhuansu > 5){
							if(speed*3.6<500 && speed >=0){
								
								that.juli  = parseInt(speed*3.6);
								
								if(that.juli >0){
									that.sen_gps(res.latitude,res.longitude,that.juli,that.time_che);
								}
								
								if(app.globalData.max_zs_time == 2){
									//当前是否最高转速
									if(that.juli > app.globalData.max_zs){
										console.log("检测到最高车速",'车速'+that.juli+" 时间:"+that.dumiao*0.01,777777777777)
										app.globalData.max_zs = that.juli;
										app.globalData.max_zs_miao = that.dumiao*0.01;
									}
								}
							}
						}else{
							that.juli = 0;
						}
						
				        //计算距离的方法调用建议写这
				     }
				    wx.startLocationUpdate({
				        success: (res) => {
				            wx.onLocationChange(_locationChangeFn)
				        },
				        fail: (err) => {
				            // 重新获取位置权限
				            wx.openSetting({
				                success(res) {
				                    res.authSetting = {
				                        "scope.userLocation": true
				                    }
				                }
				            })
				            console.log("location——err",err)
				        }
				    })
				
				return;
				
			},
			//传数据经纬度到后台
			sen_gps(lat,lng,speed,time){
				
				//time_che
				//设置位置时间
				
				let _this = this;
				this.$api.request('/api/user/sen_gps', {lat:lat,lng:lng,sd:speed}, '', function(res){
					 console.log(res);
				});
				
				// console.log(speed,this.userinfo.max_speed,time);
				// if(speed > this.userinfo.max_speed){
				// 	// 
				// 	 this.userinfo.max_speed  = speed;
				// 	//上传最高速度
				// 	this.$api.request('/api/user/max_speed', {max_speed:speed,time:this.time}, '', function(res){
				// 		 console.log(res);
						
				// 	});
				// }
				
			},
			
			get_home_data(){
				
				uni.onBLECharacteristicValueChange((res) => {
					
				   const value = Array.prototype.map.call(new Uint8Array(res.value), (bit) => bit)
				   
				   
				   console.log("监听到的数据",value)
				   console.log("监听到的数据 cl",this.$util.ab2hext(value))
					
				   let checkpage = app.globalData.checkpage;
				   let lenth = value.length;
				   if(!checkpage){
					app.globalData.mare_data = this.$util.ab2hext(value);
					
					//是否有后续的值？
					if(lenth >= 25 && lenth < 43){
						console.log("需要继续处理？");
						//是否还有后须针  需要重新组合数据 最后再分割
						app.globalData.checkpage = 1;
					}else{
						console.log("直接处理？");
						//可以直接处理了
						this.cl_datas(app.globalData.mare_data);
					}
				   }else{
						
					let data1 = app.globalData.mare_data;
					app.globalData.mare_data = app.globalData.mare_data + this.$util.ab2hext(value);
				   
					if(lenth >= 25 && lenth < 43){
						//等待处理
						console.log("需要继续处理++？");
						app.globalData.checkpage++;
					}else{
						//可以处理
						console.log("不需要继续处理？");
						this.cl_datas(app.globalData.mare_data);
					}
				   }
					// this.funReadPage(value)
				  // this.Rec_data_deal(value);
				})
			},
			cl_datas(){
				
			  let cl_data = app.globalData.mare_data;
			  app.globalData.checkpage = 0;
			  app.globalData.mare_data = null;
		
			  let hexString = cl_data; // 要分割的十六进制字符串
			  let splitResult = []; // 存放分割结果的数组
			  
			  hexString.match(/.{2}/g).forEach((item) => {
				  splitResult.push(item);
			  });
			  
			  console.log(splitResult,9797);
			  
			   //故障
			   let guzhang_1  = splitResult[8];
			   let guzhang_2  = splitResult[9];
			   let guzhang_3  = splitResult[10];
			   let guzhang_4  = splitResult[11];
			   
			   console.log(972,splitResult[13]+splitResult[12])
			   
			   //母线电压 
			   this.muxian_v = parseInt(splitResult[13]+splitResult[12],16)*0.1;
			   console.log("muxian_v",this.muxian_v)	
			   //母线电流
			   this.muxian_a = parseInt(splitResult[15]+splitResult[14],16)*0.1-1500;
			   console.log("muxian_a",this.muxian_a)	
			  
			   //电机转速
			   this.zhuansu = parseInt(splitResult[17]+splitResult[16],16)-20000;
			   console.log("zhuansu",this.zhuansu)	
			   
			   if(app.globalData.max_zs_time == 1){
					console.log("检测转速开始,",1111);
					//当前是否最高转速
					if(that.zhuansu >= 15){
						that.is_chesu();
					}
			   }
			   
			   if(app.globalData.max_zs_time == 2){
				   //结束？
				   if(that.zhuansu <=0){
						that.end_jiasu();
				   }
			   }
			   
			   
			   //相电流   
			   this.xiangxian = parseInt(splitResult[19]+splitResult[18],16)*0.1-3000;
			   console.log("xiangxian",this.xiangxian)	
			  
			   //弱磁电流
			   let ruoci = parseInt(splitResult[21]+splitResult[20],16)*0.1-3000;
				console.log("ruoci",this.ruoci)	
				
			   //mos温度  
				this.mos = parseInt(splitResult[29]+splitResult[28],16)*0.1-60;
				console.log("mos",this.mos)	
				
				//电机温度
				this.dianji = parseInt(splitResult[31]+splitResult[30],16)*0.1-60;
				console.log("dianji",this.dianji)	
				
				//油门电压
				this.dianya = parseInt(splitResult[33]+splitResult[32],16)*0.01;
				console.log("dianya",this.dianya)	
				
				
				
				// app.globalData.connected
			},
			heartbeat(){
				
				
			  let that = this;
				//AA 0C 00 10 01 1F 00 00 00 00 00 00 DB 79 
			   console.log("读秒归0")
				//0xdb, 0x79,
				// 0 - 255
				console.log(this.h_i,9711)
				if(this.h_i>=99){
					this.h_i = 0;
				}else{
					this.h_i++;
				}
				this.get_home_data();
				//0xaa,  0x0c,    0x00,    0x10,     0x01, 0x01
				//报文头	 报文长度   帧序列号	帧数据	设备id ，报文命令
				 let temp = this.$util.CRC16Modbus([
						0xaa,0x0c,0x00, 0x10, 0x01, 0x01, parseInt(this.h_i,16), this.h_f, 0x00, 0x00, 0x00, 0x00
				 ]);
				 console.log("发送心跳",temp)		
				 let strArray = new Uint8Array(temp)
				
				 const buffer = strArray.buffer
			  
				// const buffer = new ArrayBuffer(1)
				// const dataView = new DataView(buffer)
				// dataView.setUint8(0, 0)
			  
				// 向低功耗蓝牙设备特征值中写入二进制数据
				uni.writeBLECharacteristicValue({
				  // 这里的 deviceId 需要在 getBluetoothDevices 或 onBluetoothDeviceFound 接口中获取
				  deviceId: this.deviceInfo.deviceId,
				  // 这里的 serviceId 需要在 getBLEDeviceServices 接口中获取
				  serviceId: this.serviceInfo.uuid,
				  // 这里的 characteristicId 需要在 getBLEDeviceCharacteristics 接口中获取
				  characteristicId: this.writeCharacteristicsInfo.uuid,
				  // 这里的value是ArrayBuffer类型
				  value: buffer,
				  writeType: 'writeNoResponse',
				  success(res) {
					console.log("发送成功")
					console.log('writeBLECharacteristicValue success', res.errMsg)
				 
				  },
				  fail(error) {
						uni.hideLoading();	
					console.log('fail')
					console.log(error)
				  
					if (error.errCode) {
					  uni.showToast({ title: errorCode[error.errCode], icon: 'none' })
					} else if (error.errMsg) {
					  uni.showToast({ title: error.errMsg, icon: 'none' })
					} else {
					  uni.showToast({ title: 'fail', icon: 'none' })
					}
				  
				  },
				})
			},
			tz(url){
				uni.navigateTo({
					url:url
				})
			},
			zhuang() {

				var demoData = [{
					name: '功率输出',
					unit: '%',
					value: (120 / 160) * 100, // 使仪表盘指向 120
				}, ];

				this.option = {
					backgroundColor: '#19253E',
					series: (function() {
						var result = [];

						demoData.forEach(function(item) {
							result.push({
								name: item.name,
								type: 'gauge',
								radius: '100%',
								startAngle: 225,
								endAngle: -45,
								min: 0,
								max: 160,
								axisLine: {
									show: true,
									lineStyle: {
										width: 5,
										shadowBlur: 10,
										color: (() => {
											const duan = 8 // 分 8 段
											const arr = []
											for (let index = 1; index <= duan; index++) {
												arr.push([index / duan - 0.001, '#fff'])
												arr.push([index / duan + 0.001, 'transparent'])
											}
											// console.log(arr)
											return arr
										})(),
									}
								},
								axisTick: {
									show: 0,
								},
								splitLine: {
									show: 0,
								},
								axisLabel: {
									show: 0
								},
								pointer: {
									show: false,
								},
								detail: {
									show: false,
								},
								data: [{
									show: false,
								}]
							}, {
								name: item.name,
								type: 'gauge',
								radius: '50.10%',
								startAngle: 225,
								endAngle: -45,
								min: 0,
								max: 100,
								axisLine: {
									show: true,
									lineStyle: {
										width: 15,
										color: [
											[
												item.value / 100, new echarts.graphic
												.LinearGradient(
													0, 1, 1, 0, [{
															offset: 0,
															color: 'rgba(255, 36, 74,0)',
														}, {
															offset: 0.3,
															color: 'rgba(255, 36, 74,0)',
														},
														{
															offset: 1,
															color: 'rgba(255, 36, 74,1)',
														}
													]
												)
											],
											[
												1, 'rgba(255,255,255,.0)'
											]
										],
									}
								},
								axisTick: {
									show: 0,
								},
								splitLine: {
									show: 0,
								},
								axisLabel: {
									show: 0
								},
								pointer: {
									show: true,
									length: '100%'
								},
								detail: {
									show: true,
									offsetCenter: [0, '80%'],
									textStyle: {
										fontSize: 24,
										color: '#19253E'
									},

								},
								itemStyle: {
									color: 'rgba(255, 36, 74,.3)',
									borderColor: 'rgba(255, 36, 74,1)',
								},
								data: [{
									value: item.value
								}]
							}, {
								type: 'gauge',
								radius: '93.33%',
								splitNumber: 8,
								min: 0,
								max: 160,
								startAngle: 225,
								endAngle: -45,
								axisLine: {
									show: true,
									lineStyle: {
										width: 3,
										color: [
											[1,
												new echarts.graphic.LinearGradient(0, 0, 1,
													0,
													[

														{
															offset: 0,
															color: '#747474'
														},
														{
															offset: 1,
															color: '#747474'
														}
													])
											]
										],
									}
								},
								axisLabel: {
									distance: 6,
									textStyle: {
										color: '#fff',
										fontSize: '14'
									}
								},
								splitLine: {
									show: true,
									length: 16,
									lineStyle: {
										color: "#fff",
									}
								},
								pointer: {
									show: 0
								},
								detail: {
									show: 0
								}
							}, );
						});

						return result;
					})()
				}

				// this.$refs.chart.setOption(this.option)
				// 图表实例
				// myChart.setOption(this.option)

				this.init(echarts, chart => {
					chart.setOption(this.option);
				});


			},
			async init() {
				// chart 图表实例不能存在data里
				const chart = await this.$refs.chartRef.init(echarts);
				chart.setOption(this.option)
			},
			getServerData() {
				//模拟从服务器获取数据时的延时
				setTimeout(() => {
					//模拟服务器返回数据，如果数据格式和标准格式不同，需自行按下面的格式拼接
					let res = {
						categories: [{
							"value": 0.2,
							"color": "#1890ff"
						}, {
							"value": 0.8,
							"color": "#2fc25b"
						}, {
							"value": 1,
							"color": "#f04864"
						}],
						series: [{
							name: "完成率",
							data: 0.66
						}]
					};
					this.chartData = JSON.parse(JSON.stringify(res));
				}, 500);
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {}

	.home {
		background: #19253E;
		min-height: 100vh;
		width: 100%;

		.nav_top {
			padding-top: 20rpx;
			display: flex;
			justify-content: space-between;
			color: #fff;
			width: 88%;
			margin-left: 6%;
			font-size: 28rpx;
			z-index: 10;

			text {
				color: #4F7AFD;
			}

			;

			.nav_top_center {
				height: 48rpx;
				line-height: 48rpx;
			}
			
			.nav_top_left,
			.nav_top_right {

				font-family: PingFang SC, PingFang SC;
				font-weight: 600;
				line-height: 28rpx;
				width: 144rpx;
				height: 48rpx;
				background: rgba(255, 255, 255, 0.2);
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				opacity: 1;
				background: rgba(255, 255, 255, 0.2);
				text-align: center;
				line-height: 48rpx;
			}
			.nav_top_right {
				display: flex;
				justify-content: center;
				align-items: center;
				.top-icon-wrap {
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
					overflow: hidden;
				}
				.top-icon {
					width: 32rpx;
					height: 32rpx;
					margin-left: -32rpx;
					filter: drop-shadow(32rpx 0 0 #4F7AFD);
				}
			}
			.act_ctl{
				background: #4F7AFD;
				text{
					color: #fff !important;
				}
				.top-icon {
					filter: drop-shadow(32rpx 0 0 #fff);
				}
			}
		}

		.tubiao {
			width: 100%;
			height: 550rpx;
			margin-top: 40rpx;

			.tubiao_top {
				position: relative;
				top: -200rpx;
				width: 100%;
				text-align: center;
				color: #fff;
				font-size: 28rpx;
				font-weight: 500;

				text {
					font-size: 38rpx;
					margin-right: 10rpx;
				}

				;
			}

			.tubiao_bom {
				position: relative;
				top: -150rpx;
				background: #19253E;
				padding-bottom: 100px;

				.tubiao_bom_one {
					display: flex;
					flex-direction: row;
					/* 把主轴设置成y轴 */
					width: 60%;
					margin-left: 20%;
					align-items: center;
					/* 侧轴上的元素居中对齐(注意只有一个元素) */
					justify-content: space-around;

					/* 主轴上的元素居中对齐 (调整位置) */
					view {
						width: 72rpx;
						height: 48rpx;
						line-height: 48rpx;
						background: rgba(255, 255, 255, 0.2);
						border-radius: 4px 4px 4px 4px;
						text-align: center;
						color: #fff;
					}

					;
				}

				.tubiao_bom_two {
					margin-top: 40rpx;
					display: flex;
					justify-content: space-between;
					font-size: 28rpx;
					color: #fff;
					width: 94%;
					margin-left: 7%;
					margin-bottom: 30rpx;

					input {
						width: 180rpx;
						height: 64rpx;
						background: rgba(255, 255, 255, 0.2);
						border-radius: 8rpx;
						margin: 0 auto;
					}

					.tubiao_bom_two_left {
						width: 50%;
						text-align: center;

						image {
							width: 48rpx;
							height: 48rpx;
							margin-top: 8rpx;
						}

						.tubiao_bom_two_left_top {
							width: 100%;

						}

						.tubiao_bom_two_left_bom {
							width: 100%;
							display: flex;
							justify-content: space-evenly;
							margin-top: 20rpx;
						}
					}

					.tubiao_bom_two_right {
						font-size: 28rpx;
						color: #fff;
						text-align: center;
					}
				}

				.tubiao_bom_three {
					display: flex;
					justify-content: center;

					image {
						width: 48rpx;
						height: 48rpx;
						margin-top: 15rpx;
						margin-right: 10rpx;
					}

					color: #fff;
					font-size: 32rpx;
					margin: 0 auto;
					width: 694rpx;
					height: 88rpx;
					line-height: 88rpx;
					background: rgba(255, 255, 255, 0.2);
					border-radius: 10rpx;
				}

				.tubiao_bom_four {
					background: rgba(255, 255, 255, 0.2);
					width: 694rpx;
					margin: 0 auto;
					border-radius: 10rpx;
					margin-top: 20rpx;

					.tubiao_bom_four_top {
						display: flex;
						justify-content: center;

						view {
							width: 50%;
							text-align: center;
							margin: 0 auto;

							view {
								margin-top: 15rpx;
								font-size: 28rpx
							}
						}

						;
						color: #fff;
						font-size: 28rpx;
						margin: 0 auto;
						padding-top: 10rpx;
						padding-bottom: 20rpx;

						.line {
							width: 1rpx;
							height: 90rpx;
							margin-top: 20rpx;
							background-color: rgba(255, 255, 255, 0.2);
							;
						}
					}

					.lines {
						width: 90%;
						margin-left: 5%;
						height: 1rpx;
						background-color: rgba(255, 255, 255, 0.2);
						;
					}
				}

				.tubiao_bom_five {
					display: flex;
					justify-content: flex-start;
					align-items: flex-start;
					flex-wrap: wrap;
					width: 694rpx;
					margin: 0 auto;
					margin-top: 20rpx;
				
					gap: 10px;
					view {
						text-align: center;
						height: 64rpx;
						line-height: 64rpx;
						background: rgba(255, 255, 255, 0.2);
						border-radius: 10rpx;
						padding: 5rpx 5rpx;
						color: #fff;
						min-width: 114rpx;
						margin-top: 15rpx;
						
					}
				}
			
			}
		}
	}
</style>